//
//  UIView+WindowAlert.m
//  AlertTry
//
//  Created by fanwu on 15/5/10.
//  Copyright (c) 2015年 ND. All rights reserved.
//

#import "UIView+WindowAlert.h"

@implementation UIView(WindowAlert)
- (void)addToWindow{
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    
    if (!window) {
        window = ([UIApplication sharedApplication].windows)[0];
    }
    
    UIScreen * mainScreen = [UIScreen mainScreen];
    UIView * backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(mainScreen.bounds), CGRectGetHeight(mainScreen.bounds))];
    
    backgroundView.backgroundColor = [UIColor colorWithRed:.3 green:.3 blue:.3 alpha:.5];
    [backgroundView addSubview:self];
    [window addSubview:backgroundView];
}

- (void)removeFromWindow{
    UIView * backgroundView = self.superview;
    [backgroundView removeFromSuperview];
    [self removeFromSuperview];
}
@end
